<template>
  <j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    style="top: 50px"
    cancelText="关闭"
  >
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="开始日期">
                <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="startTime_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="startTime_end"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                <!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
                <!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
                <!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
                <!--              </a>-->
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->
      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
          <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
          >项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          bordered
          :rowKey="
            (record, index) => {
              return record.detailId
            }
          "
          class="j-table-force-nowrap1"
          :scroll="{ x: true }"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: checkval }"
          @change="handleTableChange"
        >
        </a-table>
      </div>
    </a-card>
  </j-modal>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import '@/assets/less/TableExpand.less'
import moment from 'dayjs'

export default {
  name: 'SelectSparePartApplicationListModal',
  mixins: [JeecgListMixin],
  components: {},
  props: {
    modalWidth: {
      type: Number,
      required: false,
      default: 1250,
    },
    checkval: {
      type: String,
      default: 'radio',
    },
    title: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      description: '五金配件请购单选择',
      applications: {},
      visible: false,
      queryParam: {
        instant: 999,
        openState: 'Y',
      },
      dateFormat: 'YYYY-MM-DD',
      moment,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'billNo',
        },
        {
          title: '物料编号',
          align: 'center',
          dataIndex: 'materialNo',
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '规格',
          align: 'center',
          dataIndex: 'spec',
        },
        {
          title: '物料描述',
          align: 'center',
          dataIndex: 'materialDesc',
        },
        {
          title: '数量',
          align: 'center',
          dataIndex: 'num',
        },
        {
          title: '质检合格数量',
          align: 'center',
          dataIndex: 'aaa',
        },
        {
          title: '单价',
          align: 'center',
          dataIndex: 'price',
        },
        {
          title: '供应商',
          align: 'center',
          dataIndex: 'supplierName',
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'createUserName',
        },
        {
          title: '制单部门',
          align: 'center',
          dataIndex: 'sysDepartName',
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '提报人',
          align: 'center',
          dataIndex: 'applyUserName',
        },
        {
          title: '开启状态',
          align: 'center',
          dataIndex: 'openState',
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'unit',
        },
        {
          title: '使用部门',
          align: 'center',
          dataIndex: 'applyDepart',
        },
        {
          title: '到货日期',
          align: 'center',
          dataIndex: 'arriveDate',
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark',
        },
      ],
      url: {
        list: '/procurement/sparePartApplicationBill/list',
        delete: '/procurement/sparePartApplicationBill/delete',
        deleteBatch: '/procurement/sparePartApplicationBill/deleteBatch',
        exportXlsUrl: '/procurement/sparePartApplicationBill/exportXls',
        importExcelUrl: 'procurement/sparePartApplicationBill/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
      startTime_begin: '',
      startTime_end: '',
    }
  },
  created() {
    this.startTime_begin = moment().subtract(7, 'days').format(this.dateFormat)
    this.startTime_end = moment().format(this.dateFormat)
    this.$forceUpdate()
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    close() {
      this.searchReset(false)
      this.visible = false
    },
    handleSubmit() {
      this.getGoodsSelectRows()
      this.searchReset(false)
      this.onClearSelected()
      this.close()
    },
    getGoodsSelectRows() {
      let selectedRow = null
      if (this.checkval == 'radio') {
        selectedRow = this.selectionRows[0]
      } else {
        selectedRow = this.selectionRows
      }
      // let selectedRow = this.selectionRows[0];
      //传递选中的数据
      this.$emit('selectBill', selectedRow)
    },
    add() {
      this.visible = true
      this.loadData()
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'code', text: '单据编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'applicationId', text: '请购单ID', dictCode: '' })
      fieldList.push({ type: 'date', value: 'startTime', text: '开始日期' })
      fieldList.push({ type: 'date', value: 'endTime', text: '结束日期' })
      fieldList.push({ type: 'date', value: 'submissionDate', text: '提报日期' })
      fieldList.push({ type: 'string', value: 'status', text: '是否开启', dictCode: '' })
      this.superFieldList = fieldList
    },
    searchQuery() {
      this.queryParam.createTimeBg = this.startTime_begin + ' 00:00:00'
      this.queryParam.createTimeEd = this.startTime_end + ' 23:59:59'
      this.loadData()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
